package com.pfc.others;


import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
import android.util.Log;

public class MySQLiteHelper extends SQLiteOpenHelper{
	
	private static final String DATABASE_NAME = "locateme.db";
	private static final int DATABASE_VERSION = 1;
	private static final String DATABASE_CREATE_FINGERPRINT = 
			"CREATE TABLE fingerprint(" +
				"bssid TEXT, " 			+
				"place TEXT, " 			+
				"locationName TEXT, " 	+
				"media FLOAT, "			+
				"s FLOAT, "				+
				"n INTEGER, " 			+
				"PRIMARY KEY(bssid, place, locationName)" +
				"FOREIGN KEY (locationName) REFERENCES location(locationName) ON DELETE CASCADE)";
	private static final String DATABASE_CREATE_LOCATION = 
			"CREATE TABLE location("		 +
			"locationName TEXT PRIMARY KEY," +
			"longitude FLOAT,"				 +
			"latitude FLOAT)";
	private static final String DATABASE_FINGERPRINT_DROP = "DROP TABLE IF EXISTS fingerprint";
	private static final String DATABASE_LOCATION_DROP = "DROP TABLE IF EXISTS location";
	
	
	
	public MySQLiteHelper(Context c){
		super(c, DATABASE_NAME, null, DATABASE_VERSION);
	}
	
	@Override
	  public void onCreate(SQLiteDatabase database) {
		System.out.println("creando tablas");
		database.execSQL(DATABASE_CREATE_LOCATION);
		database.execSQL(DATABASE_CREATE_FINGERPRINT);
	  }

	@Override
	  public void onUpgrade(SQLiteDatabase database, int oldVersion, int newVersion) {
	    Log.w(MySQLiteHelper.class.getName(), "Upgrading database from version " + oldVersion + " to " + newVersion + ", which will destroy all old data");
	    database.execSQL(DATABASE_LOCATION_DROP);
	    database.execSQL(DATABASE_FINGERPRINT_DROP);
	    onCreate(database);
	  }
	

	
	
}

